extends Area2D

@export var direction:int = 0 # 0-left 1-right 2-up 3-down
@export var speed:int = 5
@export var width:int
@export var height:int
@onready var collision_shape_2d: CollisionShape2D = $CollisionShape2D

signal score_add(index)

func _ready() -> void:
	var rect_shape = RectangleShape2D.new()
	rect_shape.extents = Vector2(width/2, height/2)
	collision_shape_2d.shape = rect_shape

func _on_area_entered(area: Area2D) -> void:
	if area.is_in_group("ball"):
		#print(direction)
		match direction:
			2: area.vec.y = speed
			3: area.vec.y = -speed
			0: 
				area.vec.x = speed
				emit_signal("score_add",1)
			1: 
				area.vec.x = -speed
				emit_signal("score_add",1)
		
